package com.dubito.encrypt.md5;

import java.math.BigInteger;
import java.security.MessageDigest;

/**
 * @author liliang
 * @description:
 * @date 2018/5/17.
 */
public class MD5Salt {

    public static void main(String[] args) {
        String password = "helloworld";
        String salt = "Random salt";
        byte[] r = MD5Salt.toMD5((salt + password).getBytes());
        System.out.println(String.format("%032x", new BigInteger(1, r)));
    }

    public static byte[] toMD5(byte[] input) {
        MessageDigest md;
        try {
            md = MessageDigest.getInstance("MD5");
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        md.update(input);
        return md.digest();
    }
}
